//
// Created by 79816 on 2023/1/17.
//

#ifndef GRADUATION_COMMON_H
#define GRADUATION_COMMON_H
#include <stdlib.h>
#include <time.h>

#define KEY_LENGTH_BYTES (16)
#define INT_SIZE (4)
#define CHAR_SIZE (1)
#define GW_NUM (3)

// 注册完成后主网关存储结构
typedef struct mgw_store_gw_part
{
    unsigned char ID[2];
    int n;
    unsigned char k[KEY_LENGTH_BYTES];
}MGW_store_gw_part;

typedef struct mgw_store
{
    unsigned char km[KEY_LENGTH_BYTES];
    MGW_store_gw_part gw_material[GW_NUM];

}MGW_store;

// 注册完成后子网关存储结构
typedef struct gw_store
{
    unsigned char ID[2];
    unsigned char k1[KEY_LENGTH_BYTES];
    unsigned char f;
    int n;
    unsigned char mr[KEY_LENGTH_BYTES];

    int r2;
}GW_store;

// 注册阶段请求
// 子网关->主网关
typedef struct reg_request
{
    unsigned char ID[2];
}REG_request;

// 注册阶段响应
// 主网关->子网关
typedef struct reg_response
{
    unsigned char k1[KEY_LENGTH_BYTES];
    unsigned char f;
    int n;
    unsigned char mr[KEY_LENGTH_BYTES];

}REG_response;

// 认证阶段请求
// 子网关->主网关
typedef struct auth_request
{
    unsigned char ID[2];
    unsigned char i[KEY_LENGTH_BYTES];
    unsigned char j[KEY_LENGTH_BYTES];
    unsigned char mr[KEY_LENGTH_BYTES];
    unsigned char f1[KEY_LENGTH_BYTES];
    unsigned char f;
}AUTH_request;

// 认证阶段响应
// 主网关->子网关
typedef struct auth_response
{
    unsigned char d1[KEY_LENGTH_BYTES];
    unsigned char f2[KEY_LENGTH_BYTES];
}AUTH_response;

// 哈希结果与随机数异或
void hash_xor_int(unsigned char* hash, int num, unsigned char* xor_result);

// 打印十六进制数据
void print_hex(unsigned char* data, int length);

int arrayToStr(unsigned char* buf, unsigned int buflen, char* out);

#endif //GRADUATION_COMMON_H
